<?php
include 'config.inc.php';
$file = $_FILES['avatar'];
$path = 'images/avatar/';
$imgname = time() . mt_rand(1000, 9999) . '.jpg';
$result = move_uploaded_file($file['tmp_name'],$path . $imgname);
$img = 'http://' . $_SERVER['HTTP_HOST'] . '/images/avatar/' . $imgname;
$add_sql = "update wwk_chat_user set img = '{$img}' where username = '{$_POST['username']}'";
$result = mysql_query($add_sql);
if ($result) {
  $a = array(
    'code' => 1,
    'msg' => '头像设置成功'
  );
} else {
  $a = array(
    'code' => 0,
    'msg' => '头像设置失败'
  );
}
echo json_encode($a);
